<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/admin/include/init_admin.jsp" %>
<%@ page import="com.joinhawaii.admin.product.*" %>
<%
	HashList code001	= CommonUtil.getCodeList("001");	//섬코드
	HashList code002	= CommonUtil.getCodeList("002");	//상품타입
	HashList code003	= CommonUtil.getCodeList("003");	//호텔타입
	HashList code004	= CommonUtil.getCodeList("004");	//호텔등급
	HashList code006	= CommonUtil.getCodeList("006");	//상품타입
	HashList code107	= CommonUtil.getCodeList("107");	//호텔회사
	HashList codeUseYn	= CommonUtil.getCodeList("use_yn");



	String tabs_code	= StringUtil.nvl(request.getParameter("tabs_code"), "1");
	String job_type		= StringUtil.nvl(request.getParameter("job_type"),"U");

	String s_land_code		= StringUtil.nvl(request.getParameter("s_land_code"));
	String s_room_type		= StringUtil.nvl(request.getParameter("s_room_type"));
	String s_hotel_eng_name	= StringUtil.toHan(request.getParameter("s_hotel_eng_name"));

	String hotel_id		= StringUtil.nvl(request.getParameter("hotel_id"));
	String s_room_id	= StringUtil.nvl(request.getParameter("s_room_id"));
	String s_from_date	= StringUtil.nvl(request.getParameter("s_from_date"));

	HashMap infos = new HashMap();
	infos.put("hotel_id",	hotel_id);

	ProductDAO dao 		= new ProductDAO();
	HashList list 		= dao.selectHotelList(infos);

	if (list.size() > 0) {
		list.put("min_sales_price", 0, dao.selectMinPriceList(list.get("hotel_id",0)));
	}

	HashList roomList 	= dao.selectHotelRoomList(infos);

	//infos.put("room_id", s_room_id);
	//infos.put("from_date", s_from_date);
	HashList priceList	= dao.selectRoomPriceList(infos);



	//HashList roomList 	= dao.selectHotelRoomList(infos);
	//HashList priceList	= dao.selectRoomPriceList(infos);

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>조인하와이</title>
	<%@ include file="/admin/include/cssnjs.jsp"  %>
	<script type="text/javascript" src="/js/ajaxfileupload.js"></script>
	<script type="text/javascript" src="/SE2.3.1.O9858/js/HuskyEZCreator.js" charset="utf-8"></script>

	<script type="text/javascript">
	var oEditors = [];

	$(document).ready(function() {

		cfInitSE("hotel_info");
		cfInitSE("hotel_cond");
		cfInitSE("hotel_room");
		cfInitSE("hotel_envi");
		cfInitSE("hotel_etc");

		$('#s_from_date').mask('9999.99.99').datepicker();
		$('#roomPriceInsert').load('./roomPriceInsert.jsp?room_id=100492');

		//탭 초기화
		$('#tabs li[code="<%=tabs_code%>"]').removeClass('off').addClass('on');
		$('#tabs-<%=tabs_code%>').removeClass('hidden');

		/* 탭 클릭 */
		$('li', '#tabs').click(function(){
		    $('.on', '#tabs').removeClass('on').addClass('off');
		    $(this).addClass('on');

			$('#tabs-1:not(.hidden),#tabs-2:not(.hidden),#tabs-3:not(.hidden),#tabs-4:not(.hidden)').addClass('hidden');
			$('#tabs-'+$(this).attr('code')).removeClass('hidden');

			//참고사진 클릭시 SE 초기화
			if ($(this).attr('code') == '4') {
				cfInitSE("hotel_pic");
			}
		});

		$('#room').find('input, select').change(function() {
			$(this).closest('tr').find('input[name="list.job_type"][value!="C"]').val('U');
		});

		$('#price').find('input:text').live('change', function() {
			$(this).closest('tr').find('input[name="list.job_type"]').val('U');
		});

		$('#price').find('input:checkbox').live('click', function() {
			if ($(this).attr('checked') == 'checked') {
				$(this).closest('tr').find('input[name="list.job_type"]').val('D');
			} else {
				$(this).closest('tr').find('input[name="list.job_type"]').val('X');
			}
		});

	});


	function fnSave()
	{
		if (confirm(MSG_<%=job_type%>)) {
			oEditors.getById["hotel_info"].exec("UPDATE_CONTENTS_FIELD", []);
			oEditors.getById["hotel_cond"].exec("UPDATE_CONTENTS_FIELD", []);
			oEditors.getById["hotel_room"].exec("UPDATE_CONTENTS_FIELD", []);
			oEditors.getById["hotel_envi"].exec("UPDATE_CONTENTS_FIELD", []);
			oEditors.getById["hotel_etc"].exec("UPDATE_CONTENTS_FIELD", []);

			$('#saveForm').attr('action', './hotelSave.do');
			$('#saveForm').submit();
		}
	}


	function fnPicSave() {
		oEditors.getById["hotel_pic"].exec("UPDATE_CONTENTS_FIELD", []);
		$('#picSaveForm').submit();
	}

	function fnUpdateRoom() {
		if (confirm(MSG_SAVE)) {
			$('#roomSaveForm').attr('action', './hotelRoomSave.do?tabs_code=2');
			$('#roomSaveForm').submit();
		}
	}

	function fnUpdatePrice() {
		if (confirm(MSG_SAVE)) {
			$('#priceSaveForm').attr('action', './hotelPriceSave.do?tabs_code=3');
			$('#priceSaveForm').submit();
		}
	}


	function fnAddRow(gubn) {

		if (gubn == 'room') {
			var txt = '<tr>'
				+ '<td class="c">'
				+ '<input type="checkbox" name="chk" />'
				+ '<input type="hidden" name="list.job_type" value="C" />'
				+ '<input type="hidden" name="list.hotel_id" value="<%= hotel_id %>" />'
				+ '<input type="hidden" name="list.room_id" value="" />'
				+ '</td>'
				+ '<td></td>'
				+ '<td class="l"><input type="text" name="list.room_name" value="" class="wmax"/></td>'
				+ '<td><input type="text" name="list.room_desc" value="" class="wmax"/></td>'
				+ '<td><input type="text" name="list.person_cnt" value="" class="wmax r"/></td>'
				+ '<td><input type="text" name="list.sort_flag" value="" class="wmax r"/></td>'
				+ '<td class="brx"><select name="list.use_yn" class="wmax"><%= StringUtil.makeOption(codeUseYn, "") %></select></td>'
				+ '</tr>';

			$("#room").append(txt);
		}
	}

	function fnDeleteRow() {
		var chks = $('input:checkbox[name="chk"]:checked');
		for (var i = 0; i < chks.length; i++) {
			$(chks[i]).closest('tr').find('input[name="list.job_type"]').val('D');
			$(chks[i]).closest('tr').hide();
		}
	}

	function btn_Update(room_id) {
		var win = window.open("./roomPriceInsert.jsp?hotel_id=<%=hotel_id%>&room_id="+room_id, "win_room_price_insert", "width=360,height=300,status=yes,toolbar=no,menubar=no,resizable=no,location=no");
        win.focus();
	}

	function btn_SetPrice(method) {
		var factor = parseInt($('#price_factor').val());
		$('#price').find('input[name="list.cost"]').each(function() {
			if (method == "multi") {
				$(this).closest('tr').find('input[name="list.sales_price"]').val(Math.round(parseInt($(this).val())*factor));
				$(this).closest('tr').find('input[name="list.job_type"]').val('U');
			} else if (method == "plus") {
				$(this).closest('tr').find('input[name="list.sales_price"]').val(parseInt($(this).val())+factor);
				$(this).closest('tr').find('input[name="list.job_type"]').val('U');
			}
		});
	}
	</script>
</head>
<body>
<div id="wrap">
	<div id="top">
		<%@ include file="/admin/include/top.jsp" %>
	</div>
	<div id="page">
		<div id="menu">
			<%@ include file="/admin/include/leftMenu.jsp" %>
		</div>
		<div id="contents">
			<div class="menu_title">
				<h1>할인호텔</h1>
				<p>관리자 > 상품관리 > <b>할인호텔</b></p>
			</div>
			<div class="clear line_01"></div>



			<ul id="tabs" class="tab_01 mt15">
			    <li class="off"  code="1"><p>1. 기본사항</p></li>
			<%	if ("U".equals(job_type)) { %>
			    <li class="off" code="2"><p>2. 객실정보</p></li>
			    <li class="off" code="3"><p>3. 객실가격</p></li>
			    <li class="off" code="4"><p>4. 참고사진</p></li>
			<%	} %>
			</ul>


			<div id="tabs-1" class="hidden mt15">

				<form id="saveForm" method="post" action="" enctype="multipart/form-data">
				<input type="hidden" name="job_type" value="<%= job_type %>"/>
				<input type="hidden" name="tabs_code" value="<%= tabs_code %>"/>
				<input type="hidden" name="hotel_id" value="<%= list.get("hotel_id", 0) %>"/>
				<input type="hidden" name="room_cnt" value="<%= StringUtil.nvl(list.get("room_cnt",0),"0") %>"/>

				<table cellpadding="0" cellspacing="0" class="table_01 mt5">
				<colgroup>
					<col width="100px"/>
					<col width="280px"/>
					<col width="100px"/>
					<col/>
				</colgroup>
				<tbody>
					<tr>
						<th><p>영문명</p></th>
						<td>
							<input type="text" name="hotel_eng_name" value="<%= list.get("hotel_eng_name", 0) %>"  maxlength="255" class="w260"/>
						</td>
						<th><p>한글명</p></th>
						<td class="brx">
							<input type="text" name="hotel_kor_name" value="<%= list.get("hotel_kor_name", 0) %>"  maxlength="255" class="w260"/>
						</td>
					</tr>
					<tr>
						<th><p>회사명</p></th>
						<td>
							<select name="company_code" class="w120">
		        			<%= StringUtil.makeOption(code107, list.get("company_code", 0)) %>
							</select>
						</td>
						<th><p>섬위치</p></th>
						<td class="brx">
		        			<select name="land_code" class="w120">
		        			<%= StringUtil.makeOption(code001, list.get("land_code", 0)) %>
							</select>
						</td>
					</tr>
					<tr>
						<th><p>호텔등급</p></th>
						<td>
							<select name="hotel_grade" class="w120">
							<%= StringUtil.makeOption(code004, list.get("hotel_grade", 0)) %>
							</select>
						</td>
						<th><p>상품타입</p></th>
						<td class="brx">
		        			<select name="room_type" class="w120">
		        			<%= StringUtil.makeOption(code002, list.get("room_type", 0)) %>
							</select>
						</td>
					</tr>
					<tr>
						<th><p>전화</p></th>
						<td><input type="text" name="tel_no" value="<%= list.get("tel_no", 0) %>" maxlength="100" class="w260" /></td>
						<th><p>팩스</p></th>
						<td class="brx"><input type="text" name="fax_no" value="<%= list.get("fax_no", 0) %>" maxlength="100" class="w260" /></td>
					</tr>
					<tr>
						<th><p>최소가격</p></th>
						<td>$<%= StringUtil.toPrice(list.get("min_sales_price", 0)) %></td>
						<th><p>사용여부</p></th>
						<td class="brx">
							<select name="use_yn" class="w120">
		        			<%= StringUtil.makeOption(codeUseYn, list.get("use_yn", 0)) %>
							</select>
						</td>
					</tr>
					<tr>
						<th><p>특가상품</p></th>
						<td>
							<input type="checkbox" name="main_yn" value="Y" <%= StringUtil.checked("Y", list.get("main_yn", 0)) %>" /> 특가상품
						</td>
						<th><p>정렬</p></th>
						<td class="brx"><input type="text" name="sort_flag" value="<%= list.get("sort_flag", 0) %>" maxlength="3" class="w100" /></td>
					</tr>
					<tr>
						<th><p>주소</p></th>
						<td colspan="3" class="brx"><input type="text" name="addr" value="<%= list.get("addr", 0) %>" style="width:100%" maxlength="500" /></td>
					</tr>
					<tr>
						<th><p>프로모션</p></th>
						<td colspan="3" class="brx"><input type="text" name="location" value="<%= list.get("location", 0) %>" style="width:100%" maxlength="500" /></td>
					</tr>
					<tr>
						<th><p>홈페이지</p></th>
						<td colspan="3" class="brx"><input type="text" name="home_page" value="<%= list.get("home_page", 0) %>" style="width:100%" maxlength="500" /></td>
					</tr>
					<tr>
						<th><p>대표사진</p></th>
						<td colspan="3" class="brx">
						<%	if ("C".equals(job_type)) { %>
								등록후 업로드
						<%	} else { %>
							<input type="file" name="img_path_00" value="" class="w300" />
			        		<a href="<%= list.get("img_path_00",0) %>" target="_blank"><%= list.get("img_path_00",0) %></a>
			        	<%	} %>
						</td>
					</tr>
					<tr>
						<th><p>호텔정보</p></th>
						<td colspan="3" class="brx">
							<textarea name="hotel_info" id="hotel_info" style="width:860px; height:200px"><%= list.get("hotel_info", 0) %></textarea>
						</td>
					</tr>
					<tr>
						<th><p>호텔규정</p></th>
						<td colspan="3" class="brx">
							<textarea name="hotel_cond" id="hotel_cond" style="width:860px; height:200px"><%= list.get("hotel_cond", 0) %></textarea>
						</td>
					</tr>
					<tr>
						<th><p>객실정보</p></th>
						<td colspan="3" class="brx">
							<textarea name="hotel_room" id="hotel_room" style="width:860px; height:200px"><%= list.get("hotel_room", 0) %></textarea>
						</td>
					</tr>
					<tr>
						<th><p>부대시설</p></th>
						<td colspan="3" class="brx">
							<textarea name="hotel_envi" id="hotel_envi" style="width:860px; height:200px"><%= list.get("hotel_envi", 0) %></textarea>
						</td>
					</tr>
					<tr>
						<th><p>기타</p></th>
						<td colspan="3" class="brx">
							<textarea name="hotel_etc" id="hotel_etc" style="width:860px; height:200px"><%= list.get("hotel_etc", 0) %></textarea>
						</td>
					</tr>
				</tbody>
				</table>

				<div class="mt20 mb10 c">
					<a href="./hotelList.jsp?s_land_code=<%=s_land_code%>&s_room_type=<%=s_room_type%>&s_hotel_eng_name=<%=s_hotel_eng_name%>"><img src="/images/admin/btn_list.gif"/></a>
			<%	if ("U".equals(job_type)) { %>
					<a href="#nohref" onclick="fnSave()"><img src="/images/admin/btn_update.gif" /></a>
					<a href="#nohref" onclick="fnDelete()"><img src="/images/admin/btn_delete.gif" /></a>
			<%	} else if ("C".equals(job_type)) { %>
					<a href="#nohref" onclick="fnSave()"><img src="/images/admin/btn_register.gif" /></a>
			<%	} %>
				</div>

				</form>

			</div>


			<!-- 객실정보 -->
			<div id="tabs-2" class="hidden mt15">

				<form id="roomSaveForm" method="post" action="">
				<input type="hidden" name="hotel_id" value="<%= hotel_id %>" />

				<table cellpadding="0" cellspacing="0" class="table_03 mt5">
				<colgroup>
					<col width="40px"/>
					<col width="60px"/>
					<col/>
					<col width="240px"/>
					<col width="60px"/>
					<col width="60px"/>
					<col width="80px"/>
				</colgroup>
				<thead>
					<tr>
						<th><p></p></th>
						<th><p></p></th>
						<th><p>객실명</p></th>
						<th><p>프로모션</p></th>
						<th><p>인원수</p></th>
						<th><p>정렬</p></th>
						<th class="brx"><p>사용여부</p></th>
					</tr>
				</thead>
				<tbody id="room">
				<%	for (int i = 0; i < roomList.size(); i++) { %>
					<tr>
						<td class="c">
							<input type="checkbox" name="chk" />
							<input type="hidden" name="list.job_type" value="X" />
							<input type="hidden" name="list.hotel_id" value="<%= roomList.get("hotel_id", i) %>" />
							<input type="hidden" name="list.room_id" value="<%= roomList.get("room_id", i) %>" />
						</td>
						<td><%= roomList.get("room_id", i) %></td>
						<td class="l"><input type="text" name="list.room_name" value="<%= roomList.get("room_name", i) %>" class="wmax"/></td>
						<td><input type="text" name="list.room_desc" value="<%= roomList.get("room_desc", i) %>" class="wmax"/></td>
						<td><input type="text" name="list.person_cnt" value="<%= roomList.get("person_cnt", i) %>" class="wmax r"/></td>
						<td><input type="text" name="list.sort_flag" value="<%= roomList.get("sort_flag", i) %>" class="wmax r"/></td>
						<td class="brx">
							<select name="list.use_yn" class="wmax">
		        			<%= StringUtil.makeOption(codeUseYn, roomList.get("use_yn", i)) %>
							</select>
						</td>
					</tr>
				<%	} %>
				</tbody>
				</table>

				<div class="mt20 mb10 c">
					<a href="./hotelList.jsp?s_land_code=<%=s_land_code%>&s_room_type=<%=s_room_type%>&s_hotel_eng_name=<%=s_hotel_eng_name%>"><img src="/images/admin/btn_list.gif"/></a>
					<img src="/images/admin/btn_addrow.gif" style="cursor:hand" onclick="fnAddRow('room')"/>
					<img src="/images/admin/btn_delrow.gif" style="cursor:hand" onclick="fnDeleteRow()"/>
					<a href="#nohref" onclick="fnUpdateRoom()"><img src="/images/admin/btn_save.gif" /></a>
				</div>

				</form>

			</div>

			<!-- 객실가격 -->
			<div id="tabs-3" class="hidden mt15">
 
				<table cellpadding="0" cellspacing="0" class="table_01 mt15">
				<tr>
					<td class="brx r">
						<b>가격일괄수정</b>
						<input type="text" name="price_factor" id="price_factor" value="" class="w90 r"/>
						<a href="#nohref" onclick="btn_SetPrice('multi')">[곱하기]</a>
						<a href="#nohref" onclick="btn_SetPrice('plus')">[더하기]</a>
					</td>
				</tr>
				</table>

				<div class="mt10 mb10 r">

				</div>


				<form  id="priceSaveForm" method="post" action="">
				<input type="hidden" name="hotel_id" value="<%= hotel_id %>"/>
				<table cellpadding="0" cellspacing="0" class="table_03 mt5">
				<colgroup>
					<col width="60px"/>
					<col/>
					<col width="100px"/>
					<col width="100px"/>
					<col width="80px"/>
					<col width="80px"/>
					<col width="80px"/>
					<col width="80px"/>
				</colgroup>
				<tbody id="price">
					<tr>
						<th><p></p></th>
						<th><p>객실명</p></th>
						<th><p>시작일</p></th>
						<th><p>종료일</p></th>
						<th><p>원가</p></th>
						<th><p>판매가</p></th>
						<th><p>B2B</p></th>
						<th class="brx"><p>삭제</p></th>
					</tr>
				<%	for (int i = 0; i < priceList.size(); i++) { %>
					<tr>
							<td><%= priceList.get("room_id",i) %></td>
							<td class="l">
								<a href="#nohref" onclick="btn_Update('<%= priceList.get("room_id",i) %>')">
									<%= priceList.get("room_name", i) %>
								<%	if (!"".equals(priceList.get("room_desc",i))) { %>
										(<%= priceList.get("room_desc", i) %>)
								<%	} %>
								</a>
							</td>
							<td><%= StringUtil.toDate(priceList.get("from_date", i)) %></td>
							<td><%= StringUtil.toDate(priceList.get("to_date", i)) %></td>

				<%		if ("".equals(priceList.get("from_date",i))) { %>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
				<%		} else { %>
							<td>
								<input type="hidden" name="list.job_type" value="X" />
								<input type="hidden" name="list.room_id" value="<%= priceList.get("room_id", i) %>"/>
								<input type="hidden" name="list.from_date" value="<%= priceList.get("from_date", i) %>"/>
								<input type="text" name="list.cost" value="<%= priceList.get("cost", i) %>" class="wmax r"/>
							</td>
							<td><input type="text" name="list.sales_price" value="<%= priceList.get("sales_price", i) %>" class="wmax r"/></td>
							<td><input type="text" name="list.b2b_price" value="<%= priceList.get("b2b_price", i) %>" class="wmax r"/></td>
							<td><input type="checkbox" name="list.chk"/>
				<%		} %>
					</tr>
				<%	} %>
				</tbody>
				</table>
				<script>
            	func_row_merge_Item(price, 1, 1);
            	func_row_merge_Item(price, 1, 0);
				</script>

				</form>

				<div class="mt20 mb10 c">
					<a href="./hotelList.jsp?s_land_code=<%=s_land_code%>&s_room_type=<%=s_room_type%>&s_hotel_eng_name=<%=s_hotel_eng_name%>"><img src="/images/admin/btn_list.gif"/></a>
					<a href="#nohref" onclick="fnUpdatePrice()"><img src="/images/admin/btn_save.gif"  /></a>
				</div>

			</div>

			<!-- 참고사진 -->
			<div id="tabs-4" class="hidden mt15">
				<form id="picSaveForm" method="post" action="./picSave.do" enctype="multipart/form-data">
				<input type="hidden" name="pic_name" id="pic_name" value="hotel"/>
				<input type="hidden" name="pic_id" value="<%= list.get("hotel_id", 0) %>"/>
				<div class="ml10 mr10">
					<textarea name="hotel_pic" id="hotel_pic" style="width:100%; height:800px" ><%= list.get("hotel_pic", 0) %></textarea>
				</div>
				<div class="mt20 mb10 c">
					<a href="./hotelList.jsp?s_land_code=<%=s_land_code%>&s_room_type=<%=s_room_type%>&s_hotel_eng_name=<%=s_hotel_eng_name%>"><img src="/images/admin/btn_list.gif"/></a>
					<a href="#nohref" onclick="fnPicSave()"><img src="/images/admin/btn_update.gif" /></a>
				</div>
				</form>
			</div>





		</div>
	</div>
</div>

</body>
</html>
